﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the Microsoft Public License (Ms-PL).
// See accompanying file License.txt or copy at http://mews.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Mews.Application
{
    using System.Net;
    using System.Windows.Forms;

    using Mews.Application.Properties;

    /// <summary>The form that displays the properties of a host.</summary>
    internal sealed partial class HostForm : DoneCancelForm
    {
        internal HostForm(
            Form owner,
            int hostNameMaxLength,
            int userNameMaxLength,
            int emailAddressMaxLength,
            int accountNameMaxLength,
            int passwordMaxLength) :
            this(
                owner,
                hostNameMaxLength,
                userNameMaxLength,
                emailAddressMaxLength,
                accountNameMaxLength,
                passwordMaxLength,
                false)
        {
        }

        internal HostForm(
            Form owner,
            string hostName,
            int hostNameMaxLength,
            int port,
            string userName,
            int userNameMaxLength,
            string emailAddress,
            int emailAddressMaxLength,
            string accountName,
            int accountNameMaxLength,
            string password,
            int passwordMaxLength) :
            this(
                owner,
                hostNameMaxLength,
                userNameMaxLength,
                emailAddressMaxLength,
                accountNameMaxLength,
                passwordMaxLength,
                false)
        {
            this.hostNameTextBox.Text = hostName;
            this.hostNameTextBox.Enabled = false;
            this.hostPortNumericUpDown.Value = port;
            this.hostPortNumericUpDown.Enabled = false;
            this.userNameTextBox.Text = userName;
            this.emailAddressTextBox.Text = emailAddress;
            this.accountNameTextBox.Text = accountName;
            this.passwordTextBox.Text = password;
        }

        internal string HostName
        {
            get { return this.hostNameTextBox.Text; }
        }

        internal int Port
        {
            get { return (int)this.hostPortNumericUpDown.Value; }
        }

        internal string UserName
        {
            get { return this.userNameTextBox.Text; }
        }

        internal string EmailAddress
        {
            get { return this.emailAddressTextBox.Text; }
        }

        internal string AccountName
        {
            get { return this.accountNameTextBox.Text; }
        }

        internal string Password
        {
            get { return this.passwordTextBox.Text; }
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private HostForm(
            Form owner,
            int hostNameMaxLength,
            int userNameMaxLength,
            int emailAddressMaxLength,
            int accountNameMaxLength,
            int passwordMaxLength,
            bool hideCancelButton) :
            base(owner, Resources.HostProperties, false, false, hideCancelButton)
        {
            this.InitializeComponent();
            this.hostNameTextBox.MaxLength = hostNameMaxLength;
            this.userNameTextBox.MaxLength = userNameMaxLength;
            this.emailAddressTextBox.MaxLength = emailAddressMaxLength;
            this.accountNameTextBox.MaxLength = accountNameMaxLength;
            this.passwordTextBox.MaxLength = passwordMaxLength;
            this.hostPortNumericUpDown.Minimum = IPEndPoint.MinPort;
            this.hostPortNumericUpDown.Maximum = IPEndPoint.MaxPort;
        }
    }
}
